Dynamic memory management
From Cppreference
< cpp
| C++ Standard Library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Utilities library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Dynamic memory management | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contents |
[edit] Low level memory management
[edit] Allocators
Allocators are class templates encapsulating memory allocation strategy. This allows generic containers to decouple memory management from the data itself.
| Defined in header
<memory> | |||
| The default allocator. Before C++11 any allocator had to provide the interface (but not necessarily implementation), identical to one of the default allocator, also it could not have nonstatic data. In C++11 these two rules are relaxed, allocators can be implemented through allocator_traits (class template) | ||
| Provides standard interface to access the interface and properties of particular allocator (class template) | ||
| Defined in header
<scoped_allocator> | |||
| Implements multi-level allocator, which can be used in multi-level containers to specify allocator for elements in each particular level (class template) | ||
[edit] Uninitialized storage
Several utilities are provided to initialize raw storage
| Defined in header
<memory> | |||
| copies a range of objects to an uninitialized area of memory (function template) | ||
| copies a number of objects to an uninitialized area of memory (function template) | ||
| copies an object to an uninitialized area of memory (function template) | ||
| copies an object to an uninitialized area of memory (function template) | ||
[edit] Smart pointers
Smart pointers enable easier and less error prone object lifetime management.
| Defined in header
<memory> | |||
Unique pointers | |||
| provides pointer ownership semantics, i.e. only one unique_ptr object can own the given object, which is destroyed when the unique_ptr object referring to it is destroyed (class template) | ||
| default deleter for unique_ptr class template (class template) | ||
| | |||
| provides shared pointer ownership semantics, i.e. multiple shared_ptr instances can manages an object, which is destroyed when the last shared_ptr object referring to it is destroyed (class template) | ||
| holds weak reference to an object already managed by shared_ptr, i.e. the object can be destroyed even there is weak_ptr instance referring to it (class template) | ||
| allows an object to get a shared_ptr referring to itself (class template) | ||
| an exception that is thrown when accessing a weak_ptr which refers to already destroyed object (class template) | ||
auto_ptr | |||
| provides unique pointer ownership semantics. This class is deprecated, use unique_ptr instead. (class template) | ||
[edit]
Overloads of all atomic functions are provided.
[edit]
The following specialization of std::hash is provided.
| Defined in header <memory>
| ||
| template<> class hash<std::shared_ptr>;
| ||
[edit] Garbage collector support
| Defined in header
<memory> | |||
| declares that an object can not be recycled even if there is no pointer referring to it (function template) | ||
| declares that an object can not be recycled even if there is no pointer referring to it (function template) | ||
| declares that a memory area does not contain pointers (function template) | ||
| declares that a memory area can have pointers (function template) | ||
| returns the implementation's pointer safety (function template) | ||
[edit] Miscellaneous
| Defined in header
<memory> | |||
| provides interface to query information about several properties of pointer-like types (class template) | ||
| obtains actual address of an object, even if the & operator is overloaded (function template) | ||
| aligns a pointer in a buffer (function template) | ||